*******************************************
/***Since the well data from 
IHS Markit Energy and NETS data on 
business dynamics are proprietory,
we anonymize county and bank ID***/
*******************************************

cd "..."

global boom "xboom 10.g_emp#c.xboom 50.g_emp#c.xboom"
global boom_iv "xboom_iv 10.g_emp#c.xboom_iv 50.g_emp#c.xboom_iv"
global control "l_lppl l_r_labor l_r_unempl l_r_prop l_lcinc l_lcasset_sod l_clev_sod l_cliqs_sod l_ccis_sod l_ctier1_sod l_cdeps_sod"

***********************************
****NETS sample main****
clear
use data_nets_all

/*Restrict to counties without direct exposure to the shale boom (boom_county==0 & boom_adj_county==0  & boom_msa==0)*/

/*Table 1 Panel C*/
tabstat xboom if ic==1, stat(n mean sd p25 p50 p75)
tabstat xboom if ic==1 & xboom>0, stat(n mean sd p25 p50 p75)

foreach x in n_est emp_all sales_all y_emp y_sales{
sum `x', detail
}

foreach x in snest_last semp_last{
sum `x', detail
}

************
/*Table 5*/
ivreghdfe y_emp ($boom = $boom_iv), absorb(county#g_emp year) cluster(county)
est store t1
ivreghdfe y_emp $control ($boom = $boom_iv), absorb(county#g_emp year) cluster(county)
est store t2
ivreghdfe y_emp ($boom = $boom_iv), absorb(county#g_emp county#year) cluster(county)
est store t3
ivreghdfe y_emp ($boom = $boom_iv), absorb(county#naics2#g_emp naics2#year) cluster(county)
est store t4
ivreghdfe y_emp $control ($boom = $boom_iv), absorb(county#naics2#g_emp naics2#year) cluster(county)
est store t5
ivreghdfe y_emp ($boom = $boom_iv), absorb(county#naics2#g_emp county#naics2#year) cluster(county)
est store t6

/*Compute the overall R-Squared for each regression above*/
matrix R=J(1,6,0)
forval i=1/6{
cap drop e_sample 
cap drop yy
est restore t`i'
gen e_sample=e(sample)
local rss=e(rss)
local depvar=e(depvar)
cap sum `depvar' if e_sample==1
gen yy=(`depvar'-r(mean))^2
cap total yy if e_sample==1
matrix r=e(b)
matrix R[1,`i']=1-`rss'/r[1,1]
}
cap drop yy
matrix list R

************
/*Table 6*/
ivreghdfe y_sales ($boom = $boom_iv), absorb(county#naics2#g_emp naics2#year) cluster(county)
est store t1
ivreghdfe y_sales $control ($boom = $boom_iv), absorb(county#naics2#g_emp naics2#year) cluster(county)
est store t2
ivreghdfe snest_last ($boom = $boom_iv), absorb(county#naics2#g_emp naics2#year) cluster(county)
est store t3
ivreghdfe snest_last $control ($boom = $boom_iv), absorb(county#naics2#g_emp naics2#year) cluster(county)
est store t4
ivreghdfe semp_last ($boom = $boom_iv), absorb(county#naics2#g_emp naics2#year) cluster(county)
est store t5
ivreghdfe semp_last $control ($boom = $boom_iv), absorb(county#naics2#g_emp naics2#year) cluster(county)
est store t6

/*Compute the overall R-Squared for each regression above*/
matrix R=J(1,6,0)
forval i=1/6{
cap drop e_sample 
cap drop yy
est restore t`i'
gen e_sample=e(sample)
local rss=e(rss)
local depvar=e(depvar)
cap sum `depvar' if e_sample==1
gen yy=(`depvar'-r(mean))^2
cap total yy if e_sample==1
matrix r=e(b)
matrix R[1,`i']=1-`rss'/r[1,1]
}
cap drop yy
matrix list R


************
/*Table 7*/
global inter_efd "c.xboom#1.efd c.xboom#10.g_emp#1.efd c.xboom#50.g_emp#1.efd xboom c.xboom#10.g_emp c.xboom#50.g_emp"
global inter_efd_iv "c.xboom_iv#1.efd c.xboom_iv#10.g_emp#1.efd c.xboom_iv#50.g_emp#1.efd xboom_iv c.xboom_iv#10.g_emp c.xboom_iv#50.g_emp"

ivreghdfe y_emp efd#g_emp ($inter_efd = $inter_efd_iv), absorb(county#g_emp year) cluster(county)
est store t1
ivreghdfe y_emp efd#g_emp $control ($inter_efd = $inter_efd_iv), absorb(county#g_emp year) cluster(county)
est store t2
ivreghdfe y_emp ($inter_efd = $inter_efd_iv), absorb(county#naics2#g_emp naics2#year) cluster(county)
est store t3
ivreghdfe y_emp $control ($inter_efd = $inter_efd_iv), absorb(county#naics2#g_emp naics2#year) cluster(county)
est store t4

/*Compute the overall R-Squared for each regression above*/
matrix R=J(1,4,0)
forval i=1/4{
cap drop e_sample 
cap drop yy
est restore t`i'
gen e_sample=e(sample)
local rss=e(rss)
local depvar=e(depvar)
cap sum `depvar' if e_sample==1
gen yy=(`depvar'-r(mean))^2
cap total yy if e_sample==1
matrix r=e(b)
matrix R[1,`i']=1-`rss'/r[1,1]
}
cap drop yy
matrix list R

************
/*Table 8*/
global inter_crisis "c.xboom#1.crisis c.xboom#10.g_emp#1.crisis c.xboom#50.g_emp#1.crisis xboom c.xboom#10.g_emp c.xboom#50.g_emp"
global inter_crisis_iv "c.xboom_iv#1.crisis c.xboom_iv#10.g_emp#1.crisis c.xboom_iv#50.g_emp#1.crisis xboom_iv c.xboom_iv#10.g_emp c.xboom_iv#50.g_emp"

ivreghdfe y_emp crisis#g_emp ($inter_crisis = $inter_crisis_iv), absorb(county#g_emp year) cluster(county)
est store t1
ivreghdfe y_emp crisis#g_emp $control ($inter_crisis = $inter_crisis_iv), absorb(county#g_emp year) cluster(county)
est store t2
ivreghdfe y_emp crisis#g_emp ($inter_crisis = $inter_crisis_iv), absorb(county#naics2#g_emp naics2#year) cluster(county)
est store t3
ivreghdfe y_emp crisis#g_emp $control ($inter_crisis = $inter_crisis_iv), absorb(county#naics2#g_emp naics2#year) cluster(county)
est store t4

/*Compute the overall R-Squared for each regression above*/
matrix R=J(1,4,0)
forval i=1/4{
cap drop e_sample 
cap drop yy
est restore t`i'
gen e_sample=e(sample)
local rss=e(rss)
local depvar=e(depvar)
cap sum `depvar' if e_sample==1
gen yy=(`depvar'-r(mean))^2
cap total yy if e_sample==1
matrix r=e(b)
matrix R[1,`i']=1-`rss'/r[1,1]
}
cap drop yy
matrix list R

*********************
/*Table 10 Panel B*/
global inter_sba "c.xboom#c.samnt_sba c.xboom#10.g_emp#c.samnt_sba c.xboom#50.g_emp#c.samnt_sba xboom c.xboom#10.g_emp c.xboom#50.g_emp"
global inter_sba_iv "c.xboom_iv#c.samnt_sba c.xboom_iv#10.g_emp#c.samnt_sba c.xboom_iv#50.g_emp#c.samnt_sba xboom_iv c.xboom_iv#10.g_emp c.xboom_iv#50.g_emp"

ivreghdfe y_emp c.samnt_sba#g_emp ($inter_sba = $inter_sba_iv), absorb(county#g_emp year) cluster(county)
est store t1
ivreghdfe y_emp c.samnt_sba#g_emp $control ($inter_sba = $inter_sba_iv), absorb(county#g_emp year) cluster(county)
est store t2
ivreghdfe y_emp c.samnt_sba#g_emp ($inter_sba = $inter_sba_iv), absorb(county#naics2#g_emp naics2#year) cluster(county)
est store t3
ivreghdfe y_emp c.samnt_sba#g_emp $control ($inter_sba = $inter_sba_iv), absorb(county#naics2#g_emp naics2#year) cluster(county)
est store t4

/*Compute the overall R-Squared for each regression above*/
matrix R=J(1,4,0)
forval i=1/4{
cap drop e_sample 
cap drop yy
est restore t`i'
gen e_sample=e(sample)
local rss=e(rss)
local depvar=e(depvar)
cap sum `depvar' if e_sample==1
gen yy=(`depvar'-r(mean))^2
cap total yy if e_sample==1
matrix r=e(b)
matrix R[1,`i']=1-`rss'/r[1,1]
}
cap drop yy
matrix list R

*************
/*Table A3*/
*County linear trend*
ivreghdfe y_emp ($boom = $boom_iv), absorb(county#naics2#g_emp naics2#year county#c.year, tol(1e6)) cluster(county)
est store t1
ivreghdfe y_emp $control ($boom = $boom_iv), absorb(county#naics2#g_emp naics2#year county#c.year, tol(1e6)) cluster(county)
est store t2

*pretrend*
global pre_sod "pre_sod c.pre_sod#10.g_emp c.pre_sod#50.g_emp"

ivreghdfe y_emp $pre_sod ($boom = $boom_iv), absorb(county#naics2#g_emp naics2#year) cluster(county)
est store t3
ivreghdfe y_emp $pre_sod $control ($boom = $boom_iv), absorb(county#naics2#g_emp naics2#year) cluster(county)
est store t4
ivreghdfe y_emp $pre_sod ($boom = $boom_iv), absorb(county#naics2#g_emp naics2#year county#c.year, tol(1e6)) cluster(county)
est store t5
ivreghdfe y_emp $pre_sod $control ($boom = $boom_iv), absorb(county#naics2#g_emp naics2#year county#c.year, tol(1e6)) cluster(county)
est store t6

/*Compute the overall R-Squared for each regression above*/
matrix R=J(1,6,0)
forval i=1/6{
cap drop e_sample 
cap drop yy
est restore t`i'
gen e_sample=e(sample)
local rss=e(rss)
local depvar=e(depvar)
cap sum `depvar' if e_sample==1
gen yy=(`depvar'-r(mean))^2
cap total yy if e_sample==1
matrix r=e(b)
matrix R[1,`i']=1-`rss'/r[1,1]
}
cap drop yy
matrix list R


***********************************
****NETS sample by owner char****

************
/*Table 9*/
clear
use data_nets_minority

ivreghdfe y_emp $control ($boom = $boom_iv) if minority==0, absorb(county#naics2#g_emp naics2#year) cluster(county)
est store t1
ivreghdfe y_emp $control ($boom = $boom_iv) if minority==1, absorb(county#naics2#g_emp naics2#year) cluster(county)
est store t2

/*Compute the overall R-Squared for each regression above*/
matrix R=J(1,2,0)
forval i=1/2{
cap drop e_sample 
cap drop yy
est restore t`i'
gen e_sample=e(sample)
local rss=e(rss)
local depvar=e(depvar)
cap sum `depvar' if e_sample==1
gen yy=(`depvar'-r(mean))^2
cap total yy if e_sample==1
matrix r=e(b)
matrix R[1,`i']=1-`rss'/r[1,1]
}
cap drop yy
matrix list R

********
clear
use data_nets_women

ivreghdfe y_emp $control ($boom = $boom_iv) if women==0, absorb(county#naics2#g_emp naics2#year) cluster(county)
est store t3
ivreghdfe y_emp $control ($boom = $boom_iv) if women==1, absorb(county#naics2#g_emp naics2#year) cluster(county)
est store t4

/*Compute the overall R-Squared for each regression above*/
matrix R=J(1,2,0)
forval i=3/4{
cap drop e_sample 
cap drop yy
est restore t`i'
gen e_sample=e(sample)
local rss=e(rss)
local depvar=e(depvar)
cap sum `depvar' if e_sample==1
gen yy=(`depvar'-r(mean))^2
cap total yy if e_sample==1
matrix r=e(b)
matrix R[1,`i'-2]=1-`rss'/r[1,1]
}
cap drop yy
matrix list R


******************************************
****NETS sample by buz form and sector****

*************
/*Table A2*/
clear
use data_nets_incorp_manufacturing

ivreghdfe y_emp ($boom = $boom_iv), absorb(county#naics2#g_emp naics2#year) cluster(county)
est store t1
ivreghdfe y_emp $control ($boom = $boom_iv), absorb(county#naics2#g_emp naics2#year) cluster(county)
est store t2

/*Compute the overall R-Squared for each regression above*/
matrix R=J(1,2,0)
forval i=1/2{
cap drop e_sample 
cap drop yy
est restore t`i'
gen e_sample=e(sample)
local rss=e(rss)
local depvar=e(depvar)
cap sum `depvar' if e_sample==1
gen yy=(`depvar'-r(mean))^2
cap total yy if e_sample==1
matrix r=e(b)
matrix R[1,`i']=1-`rss'/r[1,1]
}
cap drop yy
matrix list R

********
clear
use data_nets_incorp_tradable

ivreghdfe y_emp ($boom = $boom_iv), absorb(county#naics2#g_emp naics2#year) cluster(county)
est store t3
ivreghdfe y_emp $control ($boom = $boom_iv), absorb(county#naics2#g_emp naics2#year) cluster(county)
est store t4

/*Compute the overall R-Squared for each regression above*/
matrix R=J(1,2,0)
forval i=3/4{
cap drop e_sample 
cap drop yy
est restore t`i'
gen e_sample=e(sample)
local rss=e(rss)
local depvar=e(depvar)
cap sum `depvar' if e_sample==1
gen yy=(`depvar'-r(mean))^2
cap total yy if e_sample==1
matrix r=e(b)
matrix R[1,`i'-2]=1-`rss'/r[1,1]
}
cap drop yy
matrix list R

***********************************
****QWI sample****
clear
use data_qwi

*************
/*Table A4*/

global control "l_lppl l_r_labor l_r_unempl l_r_prop l_lcinc l_lcasset_sod l_clev_sod l_cliqs_sod l_ccis_sod l_ctier1_sod l_cdeps_sod"

ivreghdfe y (xboom inter*_cv=xboom_iv inter*_iv) if boom_county==0 & boom_adj_county==0 & boom_msa==0, absorb(county#firmsize year) cluster(county)
estimates store t1
ivreghdfe y $control (xboom inter*_cv=xboom_iv inter*_iv) if boom_county==0 & boom_adj_county==0 & boom_msa==0, absorb(county#firmsize year) cluster(county)
estimates store t2
ivreghdfe y (xboom inter*_cv=xboom_iv inter*_iv) if boom_county==0 & boom_adj_county==0 & boom_msa==0, absorb(county#ind_naics#firmsize ind_naics#year) cluster(county)
estimates store t3
ivreghdfe y $control (xboom inter*_cv=xboom_iv inter*_iv) if boom_county==0 & boom_adj_county==0 & boom_msa==0, absorb(county#ind_naics#firmsize ind_naics#year) cluster(county)
estimates store t4

/*Compute the overall R-Squared for each regression above*/
matrix R=J(1,4,0)
forval i=1/4{
cap drop e_sample 
cap drop yy
est restore t`i'
gen e_sample=e(sample)
local rss=e(rss)
local depvar=e(depvar)
cap sum `depvar' if e_sample==1
gen yy=(`depvar'-r(mean))^2
cap total yy if e_sample==1
matrix r=e(b)
matrix R[1,`i']=1-`rss'/r[1,1]
}
cap drop yy
matrix list R






